home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / Completions / Completions Source / OS Queues / OSQueueBase.cp < prev    next >
Encoding:
Text File  |  1998-06-17  |  928 b   |  58 lines  |  [TEXT/CWIE]

  1. // OSQueueBase.cp
  2.  
  3. #ifndef OSQueueBase_h
  4. #include "OSQueueBase.h"
  5. #endif
  6. #ifndef OSQueueLinkBase_h
  7. #include "OSQueueLinkBase.h"
  8. #endif
  9. #ifndef Assert_h
  10. #include "Assert.h"
  11. #endif
  12. #ifndef OSError_h
  13. #include "OSError.h"
  14. #endif
  15. #ifndef __ERRORS__
  16. #include <Errors.h>
  17. #endif
  18.  
  19. OSQueueBase::OSQueueBase()
  20.   {
  21.     head.qFlags = 0;
  22.     head.qHead = 0;
  23.     head.qTail = 0;
  24.   }
  25.  
  26. OSQueueBase::~OSQueueBase()
  27.   {
  28.     Assert( IsEmpty() );
  29.   }
  30.  
  31. void OSQueueBase::Put( OSQueueLinkBase& link )
  32.   {
  33.     Assert( !link.queued );
  34.     link.queued = true;
  35.     Enqueue( &link, const_cast<QHdr *>( &head ) );
  36.   }
  37.  
  38. OSQueueLinkBase *OSQueueBase::Get()
  39.   {
  40.     OSQueueLinkBase *got = static_cast<OSQueueLinkBase *>( head.qHead );
  41.     
  42.     if ( got == 0 )
  43.         return 0;
  44.  
  45.     OSErr error = Dequeue( got, const_cast<QHdr *>( &head ) );
  46.     
  47.     if ( error != noErr )
  48.       {
  49.         if ( error != qErr )
  50.             DebugOSError( error );
  51.         return 0;
  52.       }
  53.     
  54.     Assert( got->queued );
  55.     got->queued = 0;
  56.     return got;
  57.   }
  58.